package dev.spb3.model;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Size;

import java.util.ArrayList;
import java.util.List;

public class Movie {
    private Long id; // 主键
    @NotBlank(message = "标题不能为空")
    @Size(max = 100, message = "标题长度不能超过100个字符")
    private String title; // 电影标题
    @NotBlank(message = "导演不能为空")
    @Size(max = 100, message = "导演长度不能超过100个字符")
    private String director; // 导演
    @Size(max = 500, message = "电影简介长度不能超过500个字符")
    private String description; // 电影简介
    private String posterUrl; // 海报图片URL

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getDirector() {
        return director;
    }

    public void setDirector(String director) {
        this.director = director;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getPosterUrl() {
        return posterUrl;
    }

    public void setPosterUrl(String posterUrl) {
        this.posterUrl = posterUrl;
    }


    // 静态列表模拟数据
    private static List<Movie> movies = new ArrayList<>();

    // 使用静态方法来模拟数据库操作

    /**
     * 获取所有电影
     * @return
     */
    public static List<Movie> getAllMovies() {
        return new ArrayList<>(movies);
    }

    /**
     * 添加电影
     * @param movie
     */
    public static void addMovie(Movie movie) {
        movie.setId((long)(movies.size() + 1));
        movies.add(movie);
    }
    /**
     * 根据ID获取电影
     * @param id
     * @return
     */
    public static Movie getMovieById(Long id) {
        return movies.stream()
                .filter(movie -> movie.getId().equals(id))
                .findFirst()
                .orElse(null);
    }
    /**
     * 根据ID删除电影
     * @param id
     */
    public static void deleteMovie(Long id) {
        movies.removeIf(movie -> movie.getId().equals(id));
    }
}
